package spring.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author guo
 */
@WebFilter(filterName = "myFilter", urlPatterns = {"/filter/hello"})
public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("filter init");
        System.out.println("filter init");
        System.out.println("filter init");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("filter doFilter");
        System.out.println("filter doFilter");
        //执行目标资源，放行
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("doFilter end");
        System.out.println("doFilter end");
    }

    @Override
    public void destroy() {
        System.out.println("filter destroy");
        System.out.println("filter destroy");
        System.out.println("filter destroy");
    }
}
